local danshou = fk.CreateSkill{
    name = "wk_heg__danshou",
}

Fk:loadTranslationTable{
    ["wk_heg__danshou"] = "胆守",
    [":wk_heg__danshou"] = "每回合限一次，当你成为其他角色使用牌的目标后，你可将手牌调整至X张，若你因此法失去牌，你对其造成1点伤害（X为你本回合成为过牌目标的次数）。",

    ["#wk_heg__danshou-damage"] = "胆守：你可以弃置 %arg 张牌，对 %dest 造成1点伤害",
    ["#wk_heg__danshou"] = "胆守：你可以摸 %arg 张牌",

    ["$wk_heg__danshou1"] = "到此为止了！",
    ["$wk_heg__danshou2"] = "以胆为守，扼敌咽喉！",
}

danshou:addEffect(fk.TargetConfirmed,{
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(danshou.name) and target == player and data.from ~= player and player:usedSkillTimes(danshou.name, Player.HistoryTurn) == 0 then
      local events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
        local use = e.data
        return table.contains(use.tos, player)
      end, Player.HistoryTurn)
      if #events > 0 then
      event:setCostData(self, { num = #events })
      return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local n = player:getHandcardNum() - event:getCostData(self).num
    if n > 0 then
      local cards = player.room:askToDiscard(player,{
          min_num = n,
          max_num = n,
          include_equip = false,
          skill_name = danshou.name,
          prompt = "#wk_heg__danshou-damage::"..data.from.id..":"..n,
          skip = true,
          cancelable = true,
      })
      if #cards == n then
        event:setCostData(self, { num = n, cards = cards })
        return true
      end
    else
      event:setCostData(self, { num = n })
      return player.room:askToSkillInvoke(player, {skill_name = danshou.name, prompt = "#wk_heg__danshou:::"..-n})
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event:getCostData(self).num > 0 then
      local to = data.from
      room:doIndicate(player.id, {data.from})
      room:throwCard(event:getCostData(self).cards, danshou.name, player, player)
      if not to.dead then
        room:damage{
          from = player,
          to = to,
          damage = 1,
          skillName = danshou.name,
        }
      end
    else
      player:drawCards(-event:getCostData(self).num, danshou.name)
    end
  end,
})

return danshou